package com.admin.kotlintest.utils

import android.content.Context
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption
import com.amap.api.location.AMapLocationListener

/**
 * Created by 吴昶 on 2018/4/19.
 */
class LocationUtils{

    companion object {
        var client:AMapLocationClient?=null

        fun getCurrentLocation(context: Context,listener:AMapLocationListener){
            client= AMapLocationClient(context)
            var option=AMapLocationClientOption()
            option.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy //高精度
            option.locationMode = AMapLocationClientOption.AMapLocationMode.Battery_Saving //低功耗
            option.isOnceLocation = true //单次定位
            option.isNeedAddress = true  //返回地址信息（默认返回地址信息）
            option.isMockEnable = true  //默认为true，允许模拟位置
            option.isLocationCacheEnable = false //关闭缓存机制

            client!!.setLocationOption(option)
            client!!.setLocationListener(listener)
            client!!.stopLocation()
            client!!.startLocation()
        }

        fun stopLocation(){
            client?.let {
                client!!.stopLocation()
            }
        }
    }
}